package com.boesch.electroOffice.dataaccess.mapper.messerli;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.boesch.electroOffice.model.messerli.Invoice;
import com.boesch.electroOffice.utils.DateUtils;

/**
 * This class mappes the rows from messerli database to a Invoice object.
 * 
 * @author Ralph Koster
 *
 */
public class InvoiceMesserliMapper implements RowMapper<Invoice>, Serializable {

	private static final long serialVersionUID = -8040942088938438525L;

	/**
	 * Mapps all rows from database to a Invoice object.
	 * 
	 * @see org.springframework.jdbc.core.RowMapper
	 */
	public Invoice mapRow(ResultSet rs, int rowNum) throws SQLException {

		Invoice invoice = new Invoice();
		invoice.setProjectNumber(rs.getInt("AUFTRAG"));
		invoice.setProjectSubject(rs.getString("KURZBEZ"));
		invoice.setShortDescription(rs.getString("KURZ_BEZ"));
		invoice.setInvoiceNumber(rs.getString("RECHN_NR"));
		invoice.setInvoiceDate(DateUtils.convertDateToLocalDate(rs.getDate("R_DATUM")));
		invoice.setInvoiceDueDate(DateUtils.convertDateToLocalDate(rs.getDate("F_DATUM")));
		invoice.setInvoiceBookingDate(DateUtils.convertDateToLocalDate(rs.getDate("B_DATUM")));
		invoice.setInvoiceSum(rs.getDouble("BETRAG"));
		invoice.setInvoicePreSum(rs.getDouble("BRUTTO"));
		invoice.setSumMaterial(rs.getDouble("MATERIAL"));
		invoice.setSumWorkingHours(rs.getDouble("ARBEIT_FR"));

		return invoice;
	}
}
